package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MeetUserMapper;
import com.ruoyi.system.domain.MeetUser;
import com.ruoyi.system.service.IMeetUserService;

/**
 * 会议人员管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@Service
public class MeetUserServiceImpl implements IMeetUserService 
{
    @Autowired
    private MeetUserMapper meetUserMapper;

    /**
     * 查询会议人员管理
     * 
     * @param id 会议人员管理主键
     * @return 会议人员管理
     */
    @Override
    public MeetUser selectMeetUserById(Long id)
    {
        return meetUserMapper.selectMeetUserById(id);
    }

    /**
     * 查询会议人员管理列表
     * 
     * @param meetUser 会议人员管理
     * @return 会议人员管理
     */
    @Override
    public List<MeetUser> selectMeetUserList(MeetUser meetUser)
    {
        return meetUserMapper.selectMeetUserList(meetUser);
    }

    /**
     * 新增会议人员管理
     * 
     * @param meetUser 会议人员管理
     * @return 结果
     */
    @Override
    public int insertMeetUser(MeetUser meetUser)
    {
        return meetUserMapper.insertMeetUser(meetUser);
    }

    /**
     * 修改会议人员管理
     * 
     * @param meetUser 会议人员管理
     * @return 结果
     */
    @Override
    public int updateMeetUser(MeetUser meetUser)
    {
        return meetUserMapper.updateMeetUser(meetUser);
    }

    /**
     * 批量删除会议人员管理
     * 
     * @param ids 需要删除的会议人员管理主键
     * @return 结果
     */
    @Override
    public int deleteMeetUserByIds(Long[] ids)
    {
        return meetUserMapper.deleteMeetUserByIds(ids);
    }

    /**
     * 删除会议人员管理信息
     * 
     * @param id 会议人员管理主键
     * @return 结果
     */
    @Override
    public int deleteMeetUserById(Long id)
    {
        return meetUserMapper.deleteMeetUserById(id);
    }

    /**
     * 更新会议人员的参会状态和签到时间
     *
     * @param meetUser 会议人员信息
     * @return 结果
     */
    @Override
    public int updateMeetUserStatus(MeetUser meetUser) {
        // 验证数据
        if (meetUser.getId() == null || meetUser.getMeetId() == null) {
            throw new ServiceException("参数错误");
        }

        // 验证记录是否存在
        MeetUser existUser = meetUserMapper.selectMeetUserById(meetUser.getId());
        if (existUser == null) {
            throw new ServiceException("记录不存在");
        }

        return meetUserMapper.updateMeetUserStatus(meetUser);
    }

    /**
     * 判断是否存在会议人员
     *
     * @param meetId  会议ID
     * @param userId  人员ID
     * @return 结果
     */
    @Override
    public boolean existByMeetIdAndUserId(Long meetId, Long userId) {
        int count = meetUserMapper.existsByMeetIdAndUserId(meetId, userId);
        return count > 0;
    }




}
